<template>
  <el-dialog v-model="dialogVisible" title="更改配置" width="40%" @close="cancelFn">
    <el-form ref="ruleFormRef" label-width="160px" :model="submitData">
      <el-form-item label="全量日志开关">
        <el-switch v-model="submitData.uploadAllLog" />
      </el-form-item>
      <el-form-item label="全量日志大小" prop="triggerId">
        <el-input-number :max="5120" v-model="submitData.allLogMaxSizeMb" style="margin-right:6px" placeholder="不超过5G"/> MB
      </el-form-item>
      <el-form-item label="德赛日志开关">
        <el-switch v-model="submitData.desayLogUpload" />
      </el-form-item>
      <el-form-item label="德赛日志大小" prop="triggerId">
        <el-input-number :max="5120" v-model="submitData.desayLogMax" style="margin-right:6px" placeholder="不超过5G"/> MB
      </el-form-item>
      <el-alert type="info" show-icon :closable="false">
        <p>注：全量日志和德赛日志大小上限5G,大于5G按5G提交。</p>
      </el-alert>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="cancelFn">取消</el-button>
        <el-button type="primary" @click="submitFn">
          提交
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ElMessage } from 'element-plus';
import { ref, reactive, toRaw } from 'vue';
import { updateStrategyLogInfoByVin } from '@/api/vinLogConfigurationApi.js'

const emit = defineEmits(['feedbackFn'])
const dialogVisible = ref(false)
const ruleFormRef = ref(null)
let submitData = reactive({
  uploadAllLog: null,
  allLogMaxSizeMb: null,
  desayLogUpload: null,
  desayLogMax: null,
  vin: ''
})
const switchVisible = (row) => {
  dialogVisible.value = true

  for (let k in row) {
    submitData[k] = row[k]
  }
  delete submitData['createBy']
  delete submitData['modifyTime']
  delete submitData['operation']

}
// 提交
const submitFn = () => {
  let updateBy = JSON.parse(localStorage.getItem('userInfo')).employeeId;
  let rawSubmitData = toRaw(submitData)
  let req = { ...rawSubmitData, updateBy }
  updateStrategyLogInfoByVin(req).then(res => {
    if (res.data.code === 200) {
      ElMessage({
        type: 'success',
        message: '配置成功'
      })
      cancelFn()
      emit('feedbackFn')
    }
  })
}
//取消 、关闭弹窗
const cancelFn = () => {
  dialogVisible.value = false
  // 表单初始化
  ruleFormRef.value.resetFields()
}

defineExpose({
  switchVisible
})
</script>

<style lang="less"></style>